package tk.mybatis.springboot.service;

import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.springboot.mapper.TActivityMapper;
import tk.mybatis.springboot.model.TActivity;

import java.util.List;

/**
 * Created by NightDream on 2017/9/11.
 */
@Service
public class ActivityService {

    @Autowired
    private TActivityMapper tActivityMapper;

    public void save(TActivity tActivity) {
        if (tActivity.getId() != null) {
            tActivityMapper.updateByPrimaryKey(tActivity);
        } else {
            tActivityMapper.insert(tActivity);
        }
    }

    public void deleteById(Integer id) {
        tActivityMapper.deleteByPrimaryKey(id);
    }

    public List<TActivity> getAll(TActivity tActivity) {
        if (tActivity.getPage() != null && tActivity.getRows() != null) {
            PageHelper.startPage(tActivity.getPage(), tActivity.getRows());
        }
        return  tActivityMapper.select(tActivity);
    }

    public TActivity getTActivity(TActivity TActivity) {
        TActivity user = tActivityMapper.selectOne(TActivity);
        return user;
    }
}
